package com.moive.news.tqnewsapplication;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.StrictMode;

import com.lzy.ninegrid.NineGridView;
import com.mob.MobSDK;
import com.moive.news.tqnewsapplication.networks.RetrofitConfig;
import com.moive.news.tqnewsapplication.utils.PicassoImageLoader;
import com.tencent.bugly.crashreport.CrashReport;
import com.umeng.analytics.MobclickAgent;

import com.zhy.http.okhttp.OkHttpUtils;

import java.io.File;
import java.util.concurrent.TimeUnit;

import cn.jpush.android.api.JPushInterface;
import cn.sharesdk.framework.ShareSDK;
import okhttp3.Cache;
import okhttp3.OkHttpClient;

/**
 * Created by Administrator on 2017/12/6.
 */

public class TqNewsApplication extends Application {
    public static TqNewsApplication mInstance;
    public static Context applicationContext;
    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        applicationContext = this;
        init();
    }

    private void init() {
        //腾讯bugly
        CrashReport.initCrashReport(getApplicationContext(), "222b71b3b4", true);
        //友盟统计
        MobclickAgent.setDebugMode(true);
//        UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE,null);
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
        //OkHttpUtils配置
        // 指定缓存路径,缓存大小100Mb
        Cache cache = new Cache(new File(TqNewsApplication.getContext().getCacheDir(), "HttpCache"),
                1024 * 1024 * 100);
        OkHttpClient okHttpClient = new OkHttpClient.Builder().cache(cache)
//                .addInterceptor(new LoggerInterceptor("TAG"))
                .connectTimeout(150000L, TimeUnit.MILLISECONDS)
                .readTimeout(150000L, TimeUnit.MILLISECONDS)
                .addInterceptor(RetrofitConfig.sLoggingInterceptor)
                .addInterceptor(RetrofitConfig.sRewriteCacheControlInterceptor)
                .addNetworkInterceptor(RetrofitConfig.sRewriteCacheControlInterceptor)
                //其他配置
                .build();
        OkHttpUtils.initClient(okHttpClient);
        //初始化九宫格
        NineGridView.setImageLoader(new PicassoImageLoader());
        //手机7.0以上拍照
        if (Build.VERSION.SDK_INT >21) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
            builder.detectFileUriExposure();
        }
        //激光推送
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        //初始化ShareSDK
        MobSDK.init(this);
    }
    public static TqNewsApplication getInstance() {
        if (mInstance == null) {
            mInstance = new TqNewsApplication();
        }
        return mInstance;
    }
    public static Context getContext() {
        return applicationContext;
    }
}
